package com.leo.chapter10;

/**
 * leftRight与rightLeft方法会发生锁顺序死锁
 * @author xuexiaolei
 * @version 2017年10月18日
 */
public class LeftRightDeadLock {
    private final Object left = new Object();
    private final Object right =  new Object();

    public void leftRight(){
        synchronized (left){
            synchronized (right){
                doSomething();
            }
        }
    }

    public void rightLeft(){
        synchronized (right){
            synchronized (left){
                doSomething();
            }
        }
    }


    private void doSomething() {
    }
}
